﻿@inherits _BaseView

<MudRTLProvider RightToLeft="@SharedLayoutSettings.IsRTL">
    <MudDialog>
        <DialogContent>
            @if (!IsLoaded)
            {
                <FormOverlay />
            }
            else
            {
                <MudCard Class="mt-2">
                    <MudPaper Elevation="25">
                        <MudToolBar Dense>
                            <MudText Color="Color.Primary">
                                @DashboardResource.StringGroup
                            </MudText>
                            <MudSpacer />
                            <MudIconButton OnClick="Close" Icon="@Icons.Material.Filled.Close" Color="Color.Error" title="@DashboardResource.StringCancel" />
                        </MudToolBar>
                    </MudPaper>
                    <MudDivider DividerType="DividerType.FullWidth" />
                    <MudCardContent>
                        <MudGrid>
                            <MudItem md="12">
                                <MudField Disabled="true" Label="@DashboardResource.StringTitle" Variant="Variant.Outlined"
                                          Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.Title">
                                    @Details.Title
                                </MudField>
                            </MudItem>
                        </MudGrid>
                    </MudCardContent>
                </MudCard>
            }
        </DialogContent>
    </MudDialog>
</MudRTLProvider>

@code {

    [CascadingParameter]
    public MudDialogInstance MudDialog { get; set; }

    private void Close() => MudDialog.Close();

    // *****************************************************

    private Group Details = new();

    [Parameter]
    public int Id { get; set; }

    protected override async Task OnInitializedAsync()
    {
        IsLoaded = false;

        try
        {
            var Callback = await Http.GetFromJsonAsync<CallbackResult<Group>>($"api/Groups/Details/{Id}");

            if (Callback.Data != null)
            {
                Details = Callback.Data;
            }
            else
            {
                Snackbar.Add(Callback.Error.ToString(), Severity.Error);
            }
        }
        catch (Exception ex)
        {
            Snackbar.Add($"{DashboardResource.StringError} : " + ex.Message, Severity.Error);
        }

        IsLoaded = true;
    }

}
